package cn.tedu.collection;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

/*测试set*/
public class TestSet {
    public static void main(String[] args) {
        Set<String> set=new HashSet<>();
        set.add("紫霞仙子");
        set.add("紫霞仙子");
        set.add("至尊宝");
        set.add("蜘蛛精");
        set.add(null);
        set.add(null);
        set.add(null);
        /*set集合中的元素都是无序的
        * set集合中的元素不能重复
        * set集合可以存null值,最多一个*/
        System.out.println(set);

        System.out.println(set.contains("唐僧"));
        System.out.println(set.isEmpty());
        System.out.println(set.remove(null));
        System.out.println(set);
        System.out.println(set.size());
        System.out.println(Arrays.toString(set.toArray()));


        Set<Object> set2 = new HashSet<>();
        set2.add("小兔纸");
        set2.add("小脑斧");
        set2.add("小海疼");
        set2.add("小狮几");
        System.out.println(set2);
        set2.addAll(set);
        System.out.println(set2);
        System.out.println(set.contains(set2));
        System.out.println(set2.contains(set));
        System.out.println(set2.removeAll(set));
        System.out.println(set2);

        Iterator<String> it = set.iterator();
        while (it.hasNext()){
            System.out.println(it.next());
        }


    }
}
